package guiCode;

import java.sql.SQLException;

import javax.swing.JLabel;
import javax.swing.table.DefaultTableCellRenderer;


import basic.ClientConsole;

import com.sun.rowset.CachedRowSetImpl;

import flexibility.CachedRowSetTableModel;
import flexibility.userData;

public class ReportCode {

	private userData userInfo = new userData();
	private ClientConsole startConnection;
	private CachedRowSetImpl crs;
	private String teacher; 
	private String className; 
	 
	
	public ReportCode(ClientConsole conn){
		super();
		
		try {
			crs = new CachedRowSetImpl();
		} catch (SQLException e) {
		
			e.printStackTrace();
		}
		setConnection(conn);
	
		}
	
	
	void setConnection(ClientConsole conn){
		this.startConnection=conn;
		
	}


	public String[] getTheacherList() {
		String  s[]=new String[1000] ;
		int i;
		userInfo.deleteAll();// reset user info
		userInfo.addData(65);
		userInfo.addData(1);
		startConnection.acceptMsg(userInfo);
		crs=startConnection.getResults();
		s[0]="Select...";
		for(i=1;i<=crs.size();i++){
			try {
				crs.next();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			try {
				s[i]=(crs.getString("teacherLastName")).concat(" ").concat(crs.getString("teacherFirstName")).concat("  ").concat(crs.getString("teacherID"));
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return s;
	}
	
	
	public String[] getClassList() {
		String  s[]=new String[1000] ;
		int i;
		userInfo.deleteAll();// reset user info
		userInfo.addData(66);
		userInfo.addData(1);
		startConnection.acceptMsg(userInfo);
		crs=startConnection.getResults();
		s[0]="Select...";
		for(i=1;i<=crs.size();i++){
			try {
				crs.next();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			try {
				s[i]=(crs.getString("className"));
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return s;
	}

/*save the selected option in comboBox (from ReportGUI). 0 - for teacherComboBox  1- for studyClassConboBox */
	public void setOptionVariable(String selectedItem, int option) {
		if(option==0)
			this.teacher= selectedItem;
		if(option==1)
			this.className= selectedItem;
	}
	
	
	
/*****************************************************************/
	public CachedRowSetImpl getTheacherStudyClasses() {
		userInfo.deleteAll();// reset user info
		userInfo.addData(66);
		userInfo.addData(1);
		startConnection.acceptMsg(userInfo);
		return crs=startConnection.getResults();
/*******************************************************************/
	}
	

}
